package logging

import (
	"fmt"
	"github.com/chenwbyx/leafserver/server/pkg/setting"
)

var (
	AppLogger     *Logger
	HTTPLogger    *Logger
	DefaultLogger *Logger
	LoginLogger   *Logger
)

const (
	MAXSIZE    = 8
	MAXBACKUPS = 2
	MAXAGE     = 7
)

// 定制日志
func Setup() {
	//定制日志
	//AppLogger = NewLogger(getLogFilePath()+setting.LogSetting.App, zapcore.InfoLevel, MAXSIZE, MAXBACKUPS, MAXAGE, true, setting.LogSetting.ServiceName)
	//HTTPLogger = NewLogger(getLogFilePath()+setting.LogSetting.Http, zapcore.InfoLevel, MAXSIZE, MAXBACKUPS, MAXAGE, true, setting.LogSetting.ServiceName)
	//DefaultLogger = NewLogger(getLogFilePath()+setting.LogSetting.Default, zapcore.InfoLevel, MAXSIZE, MAXBACKUPS, MAXAGE, true, setting.LogSetting.ServiceName)
	//LoginLogger = NewLogger(getLogFilePath()+setting.LogSetting.Login, zapcore.InfoLevel, MAXSIZE, MAXBACKUPS, MAXAGE, true, setting.LogSetting.ServiceName)

	logconfig := LogConfig{}
	logconfig.DeviceName = setting.LogSetting.ServiceName
	logconfig.Level = "DEBUG"
	logconfig.MaxSize = MAXSIZE
	AppLogger = NewLogger()
	logconfig.FilePath = getLogFilePath() + setting.LogSetting.App + ".log"
	AppLogger.SetConfig(logconfig)
	//初始化日志
	LoginLogger = NewLogger()
	logconfig.FilePath = getLogFilePath() + setting.LogSetting.Login + ".log"
	LoginLogger.SetConfig(logconfig)
	HTTPLogger = NewLogger()
	logconfig.FilePath = getLogFilePath() + setting.LogSetting.Http + ".log"
	HTTPLogger.SetConfig(logconfig)
	DefaultLogger = NewLogger()
	logconfig.FilePath = getLogFilePath() + setting.LogSetting.Default + ".log"
	DefaultLogger.SetConfig(logconfig)

}

func getLogFilePath() string {
	return fmt.Sprintf("%s%s", setting.AppSetting.RuntimeRootPath, setting.AppSetting.LogSavePath)
}
